package model;

/**
 * Class extending income, for when a card gives a player money from other players.
 * @author Group 20
 *
 */
public class PlayerToPlayer extends Income
{
	Player[] players;

	/**
	 * Constructor, adds values for description, amount and the array players.
	 * @param description: Card description
	 * @param amount: value for amount
	 * @param players: array of players
	 */
	public PlayerToPlayer(String description, int amount, Player[] players) {
		super(description, amount);
		this.players = players;
	}

	/**
	 * Calculates the income based on number of players, and withdraws set amount from each player.
	 */
	@Override
	protected int calculateIncome(int balance) {
		for(Player player: players)
		{
			player.withdraw(amount);
		}
		payment = amount*players.length;
		return payment;
	}

	/**
	 * To string method.
	 */
	@Override
	public String toString() {
		return "PlayerToPlayer ["+ super.toString() +"]";
	}
}
